"""
给定一个只包括 '('，')'，'{'，'}'，'['，']' 的字符串 s ，判断字符串是否有效。有效字符串需满足：
1.左括号必须用相同类型的右括号闭合。
2.左括号必须以正确的顺序闭合。
"""
from data_structure.stack.stacks import Stack

bracket_dict = {"(": ")", "[": "]", "{": "}"}


class Solution:

    def is_valid(self, strings):
        stack = Stack()
        for char in strings:
            if char in "([{":
                stack.push(char)
                continue
            if char in ")]}" and stack.is_empty():
                return False
            if char in ")]}" and bracket_dict.get(stack.peek()) == char:
                stack.pop()
                continue
            if char in ")]}" and bracket_dict.get(stack.peek()) != char:
                return False
        else:
            if stack.is_empty():
                return True
            else:
                return False
